﻿'Derived from an example presented by Bob Powell
'http://www.devnewsgroups.net/windowsforms/t4152-how-hide-objects-inherited-properties.aspx

Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Design
Imports System.Runtime.InteropServices
Imports System

   <ToolboxItem(False)> _
   Public Class FilteredTextBox
      Inherits System.Windows.Forms.TextBox
      Implements ICustomTypeDescriptor

      Private PropertiesToHide As String() = { _
            "AcceptsReturn", _
            "AcceptsTab", _
            "AccessibilityNotifyClients", _
            "AccessibilityObject", _
            "AccessibleDefaultActionDescription", _
            "AccessibleDescription", _
            "AccessibleName", _
            "AccessibleRole", _
            "AllowDrop", _
            "AutoCompleteCustomSource", _
            "AutoCompleteMode", _
            "AutoCompleteSource", _
            "BindingContext", _
            "Bounds", _
            "CanEnableIme", _
            "ContextMenuStrip", _
            "CharacterCasing", _
            "GenerateMember", _
            "HideSelection", _
            "ImeMode", _
            "Lines", _
            "MaxLength", _
            "Modifiers", _
            "Multiline", _
            "PasswordChar", _
            "RightToLeft", _
            "Tag", _
            "Text", _
            "ScrollBars", _
            "ShortcutsEnabled", _
            "UseSystemPasswordChar", _
            "UseWaitCursor", _
            "WordWrap" _
                     }

   <EditorBrowsable(EditorBrowsableState.Never), Browsable(False)> _
   Public Overrides Property Text() As String
      Get
         Return MyBase.Text
      End Get
      Set(ByVal value As String)
         MyBase.Text = value
      End Set
   End Property

   'Does the property filtering...
   Private Function FilterProperties(ByVal pdc As PropertyDescriptorCollection) As PropertyDescriptorCollection
      Dim adjustedProps As New PropertyDescriptorCollection(New PropertyDescriptor() {})
      Dim searchfor As String
      For Each pd As PropertyDescriptor In pdc
         searchfor = pd.Name
         If Array.Find(PropertiesToHide, Function(s As String) s = searchfor) Is Nothing Then
            adjustedProps.Add(pd)
         End If
      Next
      Return adjustedProps
   End Function


#Region "ICustomTypeDescriptor Members"
   Public Function GetConverter() As TypeConverter Implements System.ComponentModel.ICustomTypeDescriptor.GetConverter
      Return TypeDescriptor.GetConverter(Me, True)
   End Function

   Public Function GetEvents(ByVal attributes() As Attribute) As EventDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetEvents
      Return TypeDescriptor.GetEvents(Me, attributes, True)
   End Function

   Private Function GetEvents() As EventDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetEvents
      Return TypeDescriptor.GetEvents(Me, True)
   End Function

   Public Function GetComponentName() As String Implements System.ComponentModel.ICustomTypeDescriptor.GetComponentName
      Return TypeDescriptor.GetComponentName(Me, True)
   End Function

   Public Function GetPropertyOwner(ByVal pd As PropertyDescriptor) As Object Implements System.ComponentModel.ICustomTypeDescriptor.GetPropertyOwner
      Return Me
   End Function

   Public Function GetAttributes() As AttributeCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetAttributes
      Return TypeDescriptor.GetAttributes(Me, True)
   End Function

   Public Function GetProperties(ByVal attributes() As Attribute) As PropertyDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetProperties
      Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(Me, attributes, True)
      Return FilterProperties(pdc)
   End Function

   Private Function GetProperties() As PropertyDescriptorCollection Implements System.ComponentModel.ICustomTypeDescriptor.GetProperties
      Dim pdc As PropertyDescriptorCollection = TypeDescriptor.GetProperties(Me, True)
      Return FilterProperties(pdc)
   End Function

   Public Function GetEditor(ByVal editorBaseType As Type) As Object Implements System.ComponentModel.ICustomTypeDescriptor.GetEditor
      Return TypeDescriptor.GetEditor(Me, editorBaseType, True)
   End Function

   Public Function GetDefaultProperty() As PropertyDescriptor Implements System.ComponentModel.ICustomTypeDescriptor.GetDefaultProperty
      Return TypeDescriptor.GetDefaultProperty(Me, True)
   End Function

   Public Function GetDefaultEvent() As EventDescriptor Implements System.ComponentModel.ICustomTypeDescriptor.GetDefaultEvent
      Return TypeDescriptor.GetDefaultEvent(Me, True)
   End Function

   Public Function GetClassName() As String Implements System.ComponentModel.ICustomTypeDescriptor.GetClassName
      Return TypeDescriptor.GetClassName(Me, True)
   End Function
#End Region
   End Class